package com.kaluli.project.repository.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.utils.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.kaluli.project.domain.entity.KllMainOrder;
import com.kaluli.project.domain.entity.KllMainOrderDetail;
import com.kaluli.project.domain.repository.KllMainOrderDetailRepository;
import com.kaluli.project.service.KllOrderSynApiService;
import com.kaluli.system.repository.AbstractRepositorySupport;

@Repository
public class KllMainOrderDetailRepositoryImpl extends AbstractRepositorySupport<KllMainOrderDetail> implements KllMainOrderDetailRepository{

	static Logger log = Logger.getLogger(KllMainOrderDetailRepositoryImpl.class);
	
	@Override
	public void updateLogisticsDetail(String id, String express_no, String express_name, String notes,String type) {
		log.info("更新子订单物流单号:id="+id+"&&express_no="+express_no);
//		String time = DateUtils.formatDate(new Date(), "yyyyMMdd");
		int time = (int) ((new Date().getTime())/1000);
		//express_name 表示快递名称,默认是4 圆通 7是天天
		StringBuffer hql = new StringBuffer("update KllMainOrderDetail t set t.domesticOrderNumber="+express_no+",t.domesticExpressTime="+time+",t.domesticExpressType="+type+" where t.id= "+id);
		Object[] params = {};
		int flag =  this.executeHql(hql.toString(), params);
	}
	
	public void updateLogisticsDetails(String id) {
		log.info("更新子订单状态:id="+id);
//		String time = DateUtils.formatDate(new Date(), "yyyyMMdd");
		int time = (int) ((new Date().getTime())/1000);
		//express_name 表示快递名称,默认是4 圆通 7是天天
		StringBuffer hql = new StringBuffer("update KllMainOrderDetail t set status=1 where t.id= "+id);
		Object[] params = {};
		int flag =  this.executeHql(hql.toString(), params);
	}
	
	public void updateLogisticsMainOrder(String orderNumber) {
		log.info("更新主订单状态:orderNumber="+orderNumber);
		StringBuffer main = new StringBuffer("update KllMainOrder t set status=2 where t.orderNumber= "+orderNumber);
		Object[] param = {};
		this.executeHql(main.toString(), param);
	}
	
	public List<KllMainOrderDetail> getListByDetail() {
		StringBuffer hql=new StringBuffer(" from KllMainOrderDetail t  where t.payStatus=1 and t.domesticExpressType=33  ");
		Map<String,Object> params=new HashMap<String, Object>();
		return this.findHqlForMap(hql.toString(), params);
	}


	@Override
	protected Class<KllMainOrderDetail> getEntityClass() {
		// TODO Auto-generated method stub
		return KllMainOrderDetail.class;
	}
	
}
